import 'package:equatable/equatable.dart';

part 'result.dart';

abstract class CheckIfExerciseCompleted {
  ExerciseCompletionCheckResult call({
    required String inputText,
    required String lexicalItemTitle,
  });
}

class CheckIfExerciseCompletedImpl implements CheckIfExerciseCompleted {
  const CheckIfExerciseCompletedImpl();

  @override
  ExerciseCompletionCheckResult call({
    required String inputText,
    required String lexicalItemTitle,
  }) {
    if (inputText.length != lexicalItemTitle.length) {
      final result = ExerciseCompletionCheckResult(
        inputText: inputText,
        exerciseSucceeded: false,
        exerciseFailed: false,
      );

      return result;
    }

    if (inputText.toLowerCase() == lexicalItemTitle.toLowerCase()) {
      final result = ExerciseCompletionCheckResult(
        inputText: lexicalItemTitle,
        exerciseSucceeded: true,
        exerciseFailed: false,
      );

      return result;
    }

    final result = ExerciseCompletionCheckResult(
      inputText: inputText,
      exerciseSucceeded: false,
      exerciseFailed: true,
    );

    return result;
  }
}
